package com.study.util;

import java.util.Date;

/**
 * @author CSDN 流放深圳
 * @description 日期处理工具类
 * @create 2024-04-13 15:55
 * @since 1.0.0
 */
public class LicenceDateUtil {


    /**
     * 计算两个日期相差的天数（afterDate - beforeDate）
     * 0=日期相等，-1=前者大于后者，1=后者大于前者
     * @param beforeDate
     * @param afterDate
     * @return
     */
    public static long getDistanceOfTwoDate(Date beforeDate, Date afterDate){
        long afterTime = afterDate.getTime();
        long beforeTime = beforeDate.getTime();
        long compare = (afterTime - beforeTime) / (1000 * 60 * 60 * 24);
        return compare;
    }

    /**
     * 判断某个日期是否在区间内
     * @param beforeDate
     * @param afterDate
     * @param now
     * @return
     */
    public static boolean isIn(Date beforeDate, Date afterDate, Date now){
        long beginMills = beforeDate.getTime();
        long endMills = afterDate.getTime();
        long thisMills = now.getTime();
        return thisMills >= Math.min(beginMills, endMills) && thisMills <= Math.max(beginMills, endMills);
    }
}
